package com.example.demo.arrayLi;


public class MyArrayList<E> {


    private Object[] num = new Object[5];

    private int count = -1;

    public void add(E i){
        if(count< num.length-1){
            // 说明数组的容量还够
            num[count+1] = i;
            count++;
        }else {
            // 说明数组长度不够了
            Object[] nums2 = new Object[num.length+10];
            System.arraycopy(num,0,nums2,0,num.length);
            num = nums2;
            num[count+1] = i;
            count++;
        }
    }


    public Object get(int index){
        return num[index];
    }
}


class TestMyArrayList{

    public static void main(String[] args) {
        MyArrayList<String> m = new MyArrayList<>();
        for (int i = 0;i<9;i++){
            m.add(""+i);
        }
       for (int i  = 0;i<9;i++){
           System.out.println(m.get(i));
       }
    }
}